import java.util.Arrays;

interface Computable{//定义一个接口
    //接口中有三个抽象方法add minus elementwiseProduct
    int[] add(int[] x, int[]y);
    int[] minus(int[] x, int[]y);
    int[] elementwiseProduct(int[] x, int[]y);
}

class Vector implements Computable{//实现接口Computable
    //实现接口中的三个抽象方法
    public int[] add(int[] x, int[] y) {//向量相加
        int[] ret = new int[4];
        for (int i = 0; i < 4; i++) {
            ret[i] = x[i] + y[i];
        }
        return ret;
    }

    public int[] minus(int[] x, int[] y) {//向量相减
        int[] ret = new int[4];
        for (int i = 0; i < 4; i++) {
            ret[i] = x[i] - y[i];
        }
        return ret;
    }

    public int[] elementwiseProduct(int[] x, int[] y) {//向量的点乘
        int[] ret = new int[4];
        for (int i = 0; i < 4; i++) {
            ret[i] = x[i] * y[i];
        }
        return ret;
    }
}
public class testInterface {
    public static void main(String[] args) {
        //定义两个四维向量
        int[]x = {5,2,1,8};
        int[]y = {3,-1,0,-4};

        //创建一个Vector对象
        Vector vector = new Vector();
        //把Vector对象的引用赋给Computable声明的接口变量
        Computable computable = vector;

        //通过Arrays.toString将数组转化成字符串输出
        System.out.println("x = "+Arrays.toString(x));
        System.out.println("y = "+Arrays.toString(y));
        System.out.println();

        //通过接口变量调用被类实现的方法 -> 分别实现对x和y的相加、相减、和点乘运算
        System.out.println("addition : "+Arrays.toString(computable.add(x, y)));
        System.out.println("difference : "+Arrays.toString(computable.minus(x, y)));
        System.out.println("product : "+Arrays.toString(computable.elementwiseProduct(x, y)));
    }
}
